#pragma once

#include "../Window/UIView.h"

enum MouseClickEventType
{
	LeftClick,
	RightClick
};

enum MouseHoverEventType
{
	HoverOn,
	HoverOff
};

class EventManager
{
public:
	EventManager(UIView* view);

	void ParseKeypress(KeyEvt evt);
	void ParseMouseClickEvent(POINT point, MouseClickEventType eventType);
	void ParseMouseMovedEvent(POINT point, UIElement*& previousActiveElement);
	void ParseMouseDownEvent(POINT point, bool& mouseAlreadyDownOnElement, UIElement* previousActiveElement, UIElement*& targetElementOut);
	void ParseScrollWheelsEvent(short scroll_delta);

	~EventManager();

private:
	UIView* view = nullptr;
	bool Intersect(UIElement* first, UIElement* second);
	bool Intersect(UIElement* elem, POINT point);
	std::vector<UIElement*> GetMousePointIntersectionTargets(std::vector<UIElement*>& elements, POINT point);
	std::vector<UIElement*> GetMousePointIntersectionTargets(std::vector<UIElement*>& elements, POINT point, std::vector<UIElement*>& missed_targets);
	UIElement* GetTopMostElement(std::vector<UIElement*>& targets);

	// Callback function prototype
	using callback_function = std::function<void(UIElement*)>;
	using keybd_callback_function = std::function<void(UIElement*, KeyEvt)>;
	using scrollwhl_callback_function = std::function<void(UIElement*, int)>;

	// different event invocations
	void invokeMouseClickEventCallback(UIElement* sender, MouseClickEventType eventType);
	void invokeMouseHoverEventCallback(UIElement* sender, MouseHoverEventType eventType);
	void invokeMouseDownEventCallback(UIElement* sender);
};

